<?php
/**
 * Formulário padrão para tela de pesquisa
 */
class App_Form_Pesquisa extends Voitech_Form
{
    protected $stBtnCadastro = true ;
    protected $stBtnImprimir = false ;
    
    /**
     * Metodo inicializador 
     * @param array $arrTipoBusca
     */
    public function __construct($stCampoTxt=true)
    {   
            parent::__construct();
            $this->setAttribs(array('name'=>'frmPesquisar','id'=>'frmPesquisar', 'class'=>'form last-child'));
            
            if( $stCampoTxt == true){
                $txtBusca = new Zend_Form_Element_Text( 'palavra_chave' );
                $txtBusca->setLabel( 'Pesquisar por:' );
                $txtBusca->setAttribs( array( 'size'=>'30' ) );
                $txtBusca->addFilter( new Zend_Filter_StringTrim() );
                $txtBusca->addFilter( new Zend_Filter_StripTags() );
                $txtBusca->setDecorators( $this->_decoratorLeft );
                $txtBusca->setRequired( true );

                $this->addElement( $txtBusca );
            }
    }
    
    public function setNoBtnCadastrar(){
       $this->stBtnCadastro = false; 
    }

    public function setYesBtnImprimir(){
       $this->stBtnImprimir = true; 
    }
        
    public function montaTipoBusca( $arrTipoBusca )
    {
            $selectBox = new Zend_Form_Element_Select( 'tipo_busca' );
            $selectBox->setLabel('Filtrar por:');
            $selectBox->setAttribs( array('class'=> 'last-child' ) );
            $selectBox->setDecorators( $this->_decoratorLeft );
            $selectBox->addMultiOptions( $arrTipoBusca );
            $selectBox->addFilters( array('StringTrim','StripTags') );
            $this->addElement( $selectBox );
    }

    protected function montaBotoes()
    {
            $button = new Zend_Form_Element_Button('Pesquisar');
            $button->setAttribs( array('class'=> 'first-child last-child','style'=>'margin-top: 17px', 'id' => 'btnPesquisar' ) );
            $button->setDecorators( $this->_decoratorLeft );
            $button->removeDecorator( 'label' );

            $this->addElement( $button );

            if($this->stBtnCadastro===true){

                $buttonCdst = new Zend_Form_Element_Button('Cadastrar');
                $buttonCdst->setAttribs( array('class'=> 'first-child last-child','style'=>'float:right; margin-top: 17px', 'id' => 'btnFrmCadastro' ) );
                $buttonCdst->setDecorators( $this->_decoratorDefault );
                $buttonCdst->removeDecorator( 'label' );

                $this->addElement( $buttonCdst );
                $this->removeDecorator( 'label' );
            }
            
                if($this->stBtnImprimir===true){

                $buttonCdst = new Zend_Form_Element_Button('Imprimir');
                $buttonCdst->setAttribs( array('class'=> 'first-child last-child','style'=>'float:right; margin-top: 17px', 'id' => 'btImprimirTela' ) );
                $buttonCdst->setDecorators( $this->_decoratorDefault );
                $buttonCdst->removeDecorator( 'label' );

                $this->addElement( $buttonCdst );
                $this->removeDecorator( 'label' );
            }            
            
    }

    protected function fieldSetGroup()
    {
        $this->addDisplayGroup(array('palavra_chave','tipo_busca','co_categoria','co_produto','co_tipo_produto','co_fornecedor','co_unidade','dt_inicio','dt_final','st_status','Pesquisar', 'Cadastrar','Imprimir'),'Filtros',array('legend' => 'Formulario de pesquisa', 'class'=>'grey-bg first-child last-child fieldset-with-legend fieldset-with-legend-first-child'));
    }

    public function setPeriodo(){
        $txtDtInicial = new Zend_Form_Element_Text( 'dt_inicio' );
        $txtDtInicial->setLabel( 'Data Inicial:' );
        $txtDtInicial->setAttribs( array( 'size'=>'10' ,'class'=>'campo_data' ) );
        $txtDtInicial->setDecorators( $this->_decoratorLeft );
         $this->addElement( $txtDtInicial );

        $txtDtFinal = new Zend_Form_Element_Text( 'dt_final' );
        $txtDtFinal->setLabel( 'Data Final:' );
        $txtDtFinal->setAttribs( array( 'size'=>'10','class'=>'campo_data' ) );
        $txtDtFinal->setDecorators( $this->_decoratorLeft );
        $this->addElement( $txtDtFinal );
    }       

   public function setSituacao(){
        $selectBox = new Zend_Form_Element_Select( 'st_status' );
        $selectBox->setLabel('Situação:');
        $selectBox->setValue('S');
        $selectBox->setAttribs( array('class'=> 'last-child' ) );
        $selectBox->setDecorators( $this->_decoratorLeft );
        $selectBox->addMultiOptions( array(''=>'Selecione','S'=>'Ativo','N'=>'Inativo') );
        $selectBox->addFilters( array('StringTrim','StripTags') );
        $this->addElement( $selectBox );				
   }             
	
    public function show()
    {

            $this->montaBotoes();
            $this->fieldSetGroup();
    }
}